﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MomentumV2
{
    class mControllerOptionsScreen : mMenuScreen
    {

        #region Instance Variables

        mMenuEntry inputMenuEntry;
        mMenuEntry forwardMenuEntry;
        mMenuEntry backwardMenuEntry;
        mMenuEntry rotateLeftMenuEntry;
        mMenuEntry rotateRightMenuEntry;
        mMenuEntry moveCrosseyeUpMenuEntry;
        mMenuEntry moveCrosseyeDownMenuEntry;
        mMenuEntry moveCrosseyeLeftMenuEntry;
        mMenuEntry moveCrosseyeRightMenuEntry;
        mMenuEntry fireMenuEntry;

        #endregion

        #region Initialization

        public mControllerOptionsScreen()
            : base("Controller Options")
        {
            inputMenuEntry = new mMenuEntry();
            forwardMenuEntry = new mMenuEntry();
            backwardMenuEntry = new mMenuEntry();
            rotateLeftMenuEntry = new mMenuEntry();
            rotateRightMenuEntry = new mMenuEntry();
            moveCrosseyeUpMenuEntry = new mMenuEntry();
            moveCrosseyeDownMenuEntry = new mMenuEntry();
            moveCrosseyeLeftMenuEntry = new mMenuEntry();
            moveCrosseyeRightMenuEntry = new mMenuEntry();
            fireMenuEntry = new mMenuEntry();
            mMenuEntry toDefaultsMenuEntry = new mMenuEntry("Reset To Defaults!");
            inputMenuEntry.Selected += InputSelected;
            toDefaultsMenuEntry.Selected += ToDefaultsSelected;
            MenuEntries.Add(inputMenuEntry);
            MenuEntries.Add(forwardMenuEntry);
            MenuEntries.Add(backwardMenuEntry);
            MenuEntries.Add(rotateLeftMenuEntry);
            MenuEntries.Add(rotateRightMenuEntry);
            MenuEntries.Add(moveCrosseyeUpMenuEntry);
            MenuEntries.Add(moveCrosseyeDownMenuEntry);
            MenuEntries.Add(moveCrosseyeLeftMenuEntry);
            MenuEntries.Add(moveCrosseyeRightMenuEntry);
            MenuEntries.Add(fireMenuEntry);
            MenuEntries.Add(toDefaultsMenuEntry);
        }

        public override void LoadContent()
        {
            inputMenuEntry.Text = "Input: " + ScreenManager.InputState.SelectedInputName;
            forwardMenuEntry.Text = "Move Forward: " + ScreenManager.InputState.ActionNameSeparated(Action.MoveForward);
            backwardMenuEntry.Text = "Move Backward: " + ScreenManager.InputState.ActionNameSeparated(Action.MoveBackward);
            rotateLeftMenuEntry.Text = "Rotate Left: " + ScreenManager.InputState.ActionNameSeparated(Action.RotateLeft);
            rotateRightMenuEntry.Text = "Rotate Right: " + ScreenManager.InputState.ActionNameSeparated(Action.RotateRight);
            moveCrosseyeUpMenuEntry.Text = "Move Crosseye Up: " + ScreenManager.InputState.ActionNameSeparated(Action.MoveCrosseyeUp);
            moveCrosseyeDownMenuEntry.Text = "Move Crosseye Down: " + ScreenManager.InputState.ActionNameSeparated(Action.MoveCrosseyeDown);
            moveCrosseyeLeftMenuEntry.Text = "Move Crosseye Left: " + ScreenManager.InputState.ActionNameSeparated(Action.MoveCrosseyeLeft);
            moveCrosseyeRightMenuEntry.Text = "Move Crosseye Right: " + ScreenManager.InputState.ActionNameSeparated(Action.MoveCrosseyeRight);
            fireMenuEntry.Text = "Fire: " + ScreenManager.InputState.ActionNameSeparated(Action.Fire);
        }

        #endregion

        #region Handle Input

        void InputSelected(object sender, EventArgs e)
        {
            switch (ScreenManager.InputState.SelectedInput)
            {
                case SelectedInput.GamePad:
                    ScreenManager.InputState.SelectedInput = SelectedInput.Keyboard;
                    break;
                case SelectedInput.Keyboard:
                    ScreenManager.InputState.SelectedInput = SelectedInput.MouseKeyboard;
                    break;
                case SelectedInput.MouseKeyboard:
                    ScreenManager.InputState.SelectedInput = SelectedInput.GamePad;
                    break;
            }
            LoadContent();
        }

        void ToDefaultsSelected(object sender, EventArgs e)
        {
            const string message = "Are you sure you want to reset to defaults?";
            mMessageBoxScreen confirmResetMessageBox = new mMessageBoxScreen(message);
            confirmResetMessageBox.Accepted += ConfirmResetMessageBoxAccepted;
            ScreenManager.AddScreen(confirmResetMessageBox);
        }

        void ConfirmResetMessageBoxAccepted(object sender, EventArgs e)
        {
            ScreenManager.InputState.SetDefaults();
        }

        #endregion

    }
}
